import type { LoginForm, LoginResponse, RecaptchaResponse } from '@/types'

import $axios from '@/sever'

// 存储短token
export const setAccessToken = (token: string) =>
  localStorage.setItem('accessToken', token)
// 存储长token
export const setRefershToken = (token: string) =>
  localStorage.setItem('refreshToken', token)
// 获取短token
export const getAccessToken = () => localStorage.getItem('accessToken')
// 获取长token
export const getRefershToken = () => localStorage.getItem('refreshToken')
// 删除短token
export const removeAccessToken = () => localStorage.removeItem('accessToken')
// 删除长token
export const removeRefershToken = () => localStorage.removeItem('refreshToken')
// 行为验证
export const checkRecaptcha = (token: string): Promise<RecaptchaResponse> => {
  return $axios.post('/users/verify-recaptcha', {
    token
  })
}
// 登录
export const login = (values: LoginForm): Promise<LoginResponse> => {
  return $axios.post('/users/login', { ...values })
}
